package utility.editor;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class AsciiLevel {
	
	public File f;
	
	public ArrayList<String> walls = new ArrayList<String>();
	public ArrayList<String> lights = new ArrayList<String>();
	
	public int width, height;
	
	public AsciiLevel(File f) {
		// build an AsciiLevel from a file (to do after LD)
	}
	
	public AsciiLevel() {
		// do nothing
	}
	
	public void saveFile(String fname) throws FileNotFoundException {
		f = new File("levels" + File.separator + fname + ".map");
		saveFile();
	}
	
	public void saveFile(){
		if(!f.exists()){
			try {
				f.createNewFile();
				
				PrintStream out = new PrintStream(f);
				
				out.println("[Dimensions]");
				out.println(width + "\t" + height);
				
				out.println("[Walls]");
				for(String s : walls){
					out.println(s);
				}
				
				out.println("[Lights]");
				for(String s : lights){
					out.println(s);
				}
				
				out.close();
			} catch (IOException e) {
				JOptionPane.showMessageDialog(null, "Could not save file!");
				System.err.println("Could not create file! Check permissions?");
			}
		}
		
		
		
	}
}
